﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for AbstractPage
/// </summary>
public abstract class AbstractPage : System.Web.UI.Page {
	public static string SESSION_USER = "user";
	protected static string REQUEST_MESSAGES = "messages";
    protected static string SEARCH_RESULTS = "searchresults";

	protected List<Message> messages;

	public List<Message> Messages {
		get { return this.messages; }
		set { this.messages = value; }
	}

	public AbstractPage() {
		List<Message> existingList = (List<Message>) this.Context.Items["messages"];
		if (existingList == null) { //No existing list carried from previous page
			existingList = new List<Message>();
		}
		this.messages = existingList;
	}

	protected void addMessage(Message message) {
		this.messages.Add(message);
		this.Context.Items[AbstractPage.REQUEST_MESSAGES] = this.messages;
	}

	protected void addMessage(Exception e) {
		this.messages.Add(new Message(Message.Type.ERROR, e.Message));
		this.Context.Items[AbstractPage.REQUEST_MESSAGES] = this.messages;
	}

	protected void addMessages(BusinessException e) {
		this.messages.AddRange(e.Messages);
		this.Context.Items[AbstractPage.REQUEST_MESSAGES] = this.messages;
	}
}
